﻿using System;
using NBpn.Network;
using NBpn.TransferFunction;
using Rhino.Mocks;
using Xunit;

namespace NBpn.Test.TransferFunction
{
    public class TransferFuncionFixture : TestFixtureBase
    {
        [Fact]
        public void SigmoidalFunction()
        {
            ITransferFunction tf = new SigmoidalTransferFuncion();

            INet net = Mock<INet>();

            using (Mocks.Record())
            {
                Expect.Call(net.Value).Return(5.0);
            }

            using (Mocks.Playback())
            {
                Assert.Equal(0.993307149, Math.Round(tf.Evaluate(net), 9));
            }
        }

        [Fact]
        public void LinealFunction()
        {
            INet net = Mock<INet>();

            ITransferFunction tf = new LinealTransferFunction();

            using (Mocks.Record())
            {
                Expect
                    .Call(net.Value)
                    .Return(5.0);
            }

            using (Mocks.Playback())
            {
                Assert.Equal(5.0, tf.Evaluate(net));
            }
        }

        [Fact]
        public void SigmoidalFunctionDerivative()
        {
            INet net = Mock<INet>();

            ITransferFunction tf = new SigmoidalTransferFuncion();

            using (Mocks.Record())
            {
                Expect
                    .Call(net.Value)
                    .Return(5.0);
            }

            using (Mocks.Playback())
            {
                //f'(net) = y * ( 1 - y )
                Assert.Equal(0.006648057, Math.Round(tf.Derivate(net), 9));
            }
        }

        [Fact]
        public void LinealFunctionDerivative()
        {
            INet net = Mock<INet>();

            ITransferFunction tf = new LinealTransferFunction();

            using (Mocks.Record())
            {
                SetupResult.For(net.Value).Return(5.0);
            }

            using (Mocks.Playback())
            {
                Assert.Equal(1.0, tf.Derivate(net));
            }
        }
    }
}